# Piglet makefile
# Builds Elsa apps without Oink!

include config.mk
include build.mk

PORK_SRCS = expr_visitor piglet patcher
PORK_OBJS = $(addsuffix .o, $(PORK_SRCS))

.PHONY: all elsa_all clean distclean

all: elsa_all stopwatch pobcpp prepobcpp

## FIXME it would be nice to pass our CXXFLAGS to the configure scripts
## of elsa et al.
$(ELSA_DIR)/Makefile:
	cd $(ELSA_DIR) && CXX="$(CXX)" ./configure

elsa_all: $(ELSA_DIR)/Makefile
	$(MAKE) -C $(ELSA_DIR)

stopwatch: stopwatch.o $(LIBPORK)
	$(CXX) $(CXXFLAGS) -o $@ $+

pobcpp: pobcpp.o  $(LIBPORK)
	$(CXX) $(CXXFLAGS) -o $@ $+

prepobcpp: prepobcpp.o pobcpp1st.o $(LIBPORK)
	$(CXX) $(CXXFLAGS) -o $@ $+

piglet.o: piglet.h

$(LIBPORK): elsa_all $(PORK_OBJS)
	cp $(LIBELSA) $@
	ar rs $@ $(PORK_OBJS)

clean:
	rm -f $(LIBPORK) stopwatch pobcpp prepobcpp *.o *~ *.pyc
	$(MAKE) -C porky clean
	for dir in smbase ast elkhound; do $(MAKE) -C $(ELSA_DIR)/$$dir clean; done
	$(MAKE) -C $(ELSA_DIR) clean

distclean: clean
	rm -f config.mk Makefile
	$(MAKE) -C porky distclean
	for dir in smbase ast elkhound; do $(MAKE) -C $(ELSA_DIR)/$$dir distclean; done
	$(MAKE) -C $(ELSA_DIR) distclean
